"""
更新图片详情
"""
import os
import sys
import django

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")
django.setup()
from apps.supply_order.models import Goods
from apps.supply_order.models import GoodsImage


class GoodsImageDetails(object):
    @classmethod
    def get_images(cls, goods_id, image_type=4, url="/shangpintupian/mingpinshijia/国台·上品/"):
        """
        :param goods_id:
        :param image_type: 4、轮播图  2、详情页
        :return:
        """
        goods_image = GoodsImage.objects.filter(goods_id=goods_id, type=image_type)
        for i in goods_image:
            path = i.path.replace("https://zaoqi.oss-cn-beijing.aliyuncs.com", "https://shop.kalaibao.com")
            file_name = path.split("/")[-1]
            host_name = path.split("shangpintupian")[0]
            host_name = host_name[:-1]
            path_url = host_name + url + file_name
            # print(path_url)
            i.path = path_url
            i.save()
            i.refresh_from_db()
            print(i.path)

    @classmethod
    def update_img(cls, goods_id, goods_type=2):
        goods_img_queryset = GoodsImage.objects.filter(goods_id=goods_id, type=goods_type)
        for i in goods_img_queryset:
            path = i.path.replace("/mingpinshijia/澳赛诗WIN9/", "/laimei/艾叶护理足贴/")
            # i.path = path
            # i.save()
            print(path)


if __name__ == '__main__':
    # 改72了 117
    GoodsImageDetails.get_images(124, image_type=4, url="/shangpintupian/jinkoujiaju/[Q0012379100]韩国原产JOODESIGN靠垫创意靠垫桌ABS塑料款/主图/")
    GoodsImageDetails.get_images(124, image_type=2, url="/shangpintupian/jinkoujiaju/[Q0012379100]韩国原产JOODESIGN靠垫创意靠垫桌ABS塑料款/详情图/")
